<?php
require_once('../connection.php');

session_start();

//dersom bruker er pålogget og aksesserer egen profil
if(isset($_SESSION['uid']))
{
	if($_SESSION['uid'] == $_GET['user'])
	{
		$id = $_GET['user'];
		$sql = 'SELECT id, username, firstname, surname, email, telephone, usertype, imageurl, website FROM user WHERE id = :id';
		$sth = $db->prepare($sql);
		$sth->bindParam(":id",$id);
		$sth->execute();
		$res = $sth->fetch();
		echo json_encode($res);
	}
	elseif($_SESSION['uid'] != $_GET['user']) //Dersom bruker pålogget og på en annen en egen profil
	{
	$id = $_GET['user'];
	$sql = 'SELECT username, firstname, surname, email, telephone, usertype, imageurl, website FROM user WHERE id = :id';
	$sth = $db->prepare($sql);
	$sth->bindParam(":id",$id);
	$sth->execute();
	$res = $sth->fetch();
	echo json_encode($res);
	}
}
elseif(!isset($_SESSION['uid'])) //Dersom bruker ikke er pålogget!
{
	$id = $_GET['user'];
	$sql = 'SELECT username, firstname, surname, usertype FROM user WHERE id = :id';
	$sth = $db->prepare($sql);
	$sth->bindParam(":id",$id);
	$sth->execute();
	$res = $sth->fetch();
	echo json_encode($res);	
}


?>